﻿using CefSharp;
using CefSharp.WinForms;
using System;
using System.IO;
using System.Windows.Forms;
using winformchrome.server.controller;

namespace winformchrome
{
    public partial class MainForm : Form
    {
        public ChromiumWebBrowser webbrowser;
        public MainForm()
        {
            InitializeComponent();
            CefSettings settings = new CefSettings();
            Cef.Initialize(settings);
            var fileName = Path.Combine(Directory.GetCurrentDirectory(), "page/index.html");
            webbrowser = new ChromiumWebBrowser(fileName) { Dock = DockStyle.Fill };

            CefSharpSettings.LegacyJavascriptBindingEnabled = true;
            webbrowser.RegisterJsObject("userController", new UserController(), new CefSharp.BindingOptions() { CamelCaseJavascriptNames = false });

            this.panel1.Controls.Add(webbrowser);
            webbrowser.Dock = DockStyle.Fill;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webbrowser.ExecuteScriptAsync("hello()");
        }
    }
}
